package com.lhc.demo.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassName Math
 * @Description:
 * @Author: asus
 * @CreateDate: 2020-11-9 14:32
 * @UpdateUser: asus
 * @UpdateDate: 2020-11-9 14:32
 * @UpdateRemark:
 * @Version: 1.0
 */
//自动生成随机数  (幸运双色球)
@RestController
public class Math {
    @RequestMapping(value = "/list")
    public List list (){
        List ssq = new ArrayList();
        //从方法，获得红球号码数组和蓝球号码数组
        List red = new ArrayList ();

        //从红球号码数组选择6个，保存得到变量red
        red = selectRed(red);
        //从蓝球号码数组选择1个，保存到变量blue
        int blue = selectBlue();

        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ssq.add("当前时间为"+sdf.format(now));
        ssq.add("红球是"+red);
        ssq.add("蓝球是"+blue);
        return ssq;

    }
    private static List selectRed(List r) {

        //保存结果的数组
        List red = new ArrayList(6);
        //标记数组
        boolean[] flag = new boolean[33];
        //遍历red数组，放入选择的红球号码
        for (int i = 0; i < 6; i++) {
            while (true){
                int a = new Random().nextInt(33)+1;
                if(red.indexOf(a) == -1){
                    red.add(a);
                    break;
                }
            }
        }
        Collections.sort(red);
        return red;
    }
    private static int selectBlue() {
        return new Random().nextInt(16)+1;
    }

}
